package com.bwie.controller;

import com.bwie.pojo.Discount;
import com.bwie.pojo.Journey;
import com.bwie.service.DiscountService;
import com.bwie.service.JourneyService;
import com.bwie.utils.QRCodeUtil;
import com.bwie.utils.R;
import com.bwie.utils.WxPayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author lenovo
 */
@RestController
@RequestMapping("/journey")
public class JourneyController {

    @Autowired
    private JourneyService journeyService;

    @Autowired
    private WxPayUtils wxPayUtils;

    @Autowired
    private DiscountService discountService;

    @PostMapping("/list")
    public R list(){
        List<Journey> journeyList = journeyService.list();
        return R.OK(journeyList);
    }
    @PostMapping("/discount")
    public R discount(){
        List<Discount> discountList = discountService.list();
        return R.OK(discountList);
    }

    @PostMapping("/add")
    public R add(@RequestBody Journey journey){
        return journeyService.add(journey);
    }

    @GetMapping("/wxpay/{orderId}")
    public void wxpay(@PathVariable String orderId, HttpServletResponse response){
        //微信支付
        String wxPay = wxPayUtils.wxPay(orderId);
        QRCodeUtil.createQRCode(response, wxPay);
    }

}
